package cn.glc.daily.life.web.factory.login.core;

import cn.glc.daily.life.infrastructure.po.UserAuthsPo;
import cn.glc.daily.life.infrastructure.repository.mysql.MysqlRepositories;
import cn.glc.daily.life.model.dto.LoginDto;
import cn.glc.daily.life.web.factory.login.AbstractLoginFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * 非三方,默认登录接口
 *
 * @author simon
 * @date 2020/11/10 14:40
 * @copyright:
 * @modifier
 * @motto a no talent, people who have to study hard
 */
@Slf4j
public class DefaultLoginFactory extends AbstractLoginFactory {

    @Override
    public Long login(LoginDto loginDto) {
        UserAuthsPo userAuthsPo = MysqlRepositories.userAuthsRepository.findByIdentifyAndType(loginDto.getIdentify(), loginDto.getType().getName());
        if (Objects.nonNull(userAuthsPo) && StringUtils.equals(loginDto.getCredential(), userAuthsPo.getCredential())) {
            return userAuthsPo.getUid();
        }
        return null;
    }

    @Override
    public Boolean match(LoginDto loginDto) {
        return null;
    }
}
